// pages/BoosReserva/BoosReserva.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: true,
        loadingconflg: false,
        nodata: false,
        page: 1,
        totalpage: 1,
        dateindex: 0,
        listdata: [],
        inputValue: "",
        ishow: false,
        state: '',
        isID: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // this.GetReserva();
    },
    GetReserva: function () {
        wx.showLoading({
            title: '加载中',
        });
        var _this = this;
        var listdata = _this.data.listdata;
        var page = _this.data.page;
        var state = _this.data.dateindex;
        app.http.POST("/MiniManagerReserva/GetEmpReservaList", { page: page, status:state }, (err, data) => {
            if (data.code == 1) {
                var list = data.data.List;
                if (typeof (data.data.TotalPage) != "undefined" && data.data.TotalPage) {
                    _this.setData({
                        "totalpage": data.data.TotalPage
                    });
                }
                if (list == null || list.length < 1) {
                    this.setData({
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": true
                    })
                } else {
                    listdata = listdata.concat(list);
                    _this.setData({
                        "listdata": listdata,
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": false
                    });
                }
            } else if (data.code == 2) {
                wx.showToast({
                    title: data.msg,
                    icon: 'none',
                    duration: 2000
                })
                _this.setData({
                    "loading": false,
                    "nodata": true
                })
            } else {
                wx.showToast({
                    title: '请求失败',
                    icon: 'none',
                    duration: 2000
                })
                _this.setData({
                    "loading": false,
                    "nodata": true
                })
            }
            wx.hideLoading();
        })
    },
    lower: function (e) {
        var _this = this;
        var page = _this.data.page + 1;
        if (page <= _this.data.TotalPage) {
            _this.setData({
                "page": page,
                "loading": true,
                "loadingconflg": true,
            })
            _this.GetReserva();
        } else {
            _this.setData({
                "loading": true,
                "loadingconflg": false,
            })
        }
    },
    DateChange: function (e) {
        var index = e.currentTarget.dataset.id;
        var _this = this;
        _this.setData({
            dateindex: index,
            page: 1,
            listdata: [],
        })
        _this.GetReserva();
    },
    backReservaDetail: function (e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/EmpReserva/ReservaDetails?id=' + id
        })
    },
    // 接受or拒绝
    accept: function (e) {
        var _this = this;
        var acp = e.currentTarget.dataset.act;
        var ids = e.currentTarget.dataset.ids;
        if (acp == 3) {
            var param = {
                "id": ids,
                "state": acp
            }
            _this.eReserva(param);
        } else {
            _this.setData({
                "ishow": true,
                "state": acp,
                "isID": ids
            })
        }
    },
    yesbnt: function () {
        var _this = this;
        if (_this.data.inputValue == "") {
            wx.showToast({
                title: '请填写理由',
                icon: 'none',
                duration: 2000
            })
        } else {
            var param = {
                "id": _this.data.isID,
                "state": _this.data.state,
                "remarks": _this.data.inputValue
            }
            _this.eReserva(param);
        }
    },
    eReserva: function (param) {
        wx.showLoading({
            title: '加载中',
        })
        app.http.POST("/MiniManagerReserva/HandleReserva", param, (err, data) => {
            if (data.code == 0) {
                this.setData({
                    listdata: [],
                    "ishow": false
                })
                this.GetReserva();
            } else if (data.code == 2) {
                wx.showToast({
                    title: data.msg,
                    icon: 'none',
                    duration: 2000
                })
            } else {
                wx.showToast({
                    title: '请求失败',
                    icon: 'none',
                    duration: 2000
                })
            }
            wx.hideLoading();
        })
    },
    bindKeyInput: function (e) {
        this.setData({
            inputValue: e.detail.value
        })
    },
    noYbnt: function () {
        this.setData({
            "ishow": false
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        wx.setNavigationBarTitle({
            title: '查看预约'
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var _this = this;
        _this.setData({
            page: 1,
            listdata: [],
        })
        _this.GetReserva();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})